//
//  TWNavigationViewController.m
//  BuDeJie
//
//  Created by 田伟 on 2017/1/19.
//  Copyright © 2017年 公司. All rights reserved.
//

#import "TWNavigationViewController.h"

@interface TWNavigationViewController ()<UIGestureRecognizerDelegate>

@end

@implementation TWNavigationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    // 控制手势什么时候触发
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    
    // 禁用掉之前的边缘滑动的手势
    self.interactivePopGestureRecognizer.enabled = NO;
    
}

// ⭐️拦截导航栏的Push操作
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

    if (self.childViewControllers.count > 0) {
        // 1将即将push的页面的返回按钮修改样式
        UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [backButton setImage:[UIImage imageNamed:@"Action_backward_44x44_"] forState:UIControlStateNormal];
        [backButton sizeToFit];
        [backButton setContentEdgeInsets:UIEdgeInsetsMake(0, -30, 0, 0)];
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
        // 2关闭底部的tabBar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    // 真正在跳转
    [super pushViewController:viewController animated:animated];
}


#pragma mark ------------以下自定义方法------------
- (void)back{
    [self popViewControllerAnimated:YES];
}

#pragma mark ------------以下为代理方法------------
#pragma mark -- UIGestureRecognizerDelegate
// 用来觉得是否触发这个手势，返回NO，永远不会触发
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    // 只有在非根控制器下才需要触发，根控制器下不需要触发
    return self.childViewControllers.count > 1;
}

@end
